﻿using System;
using System.Collections.Generic;
using System.Text;

namespace bank
{
    public delegate void BigMoneyFetchedHandler(Object sender, BigMoneyArgs args);
    public  class BigMoneyArgs
    {
       public float Money
        {
            get;
            set;
        }
    }

    class ATM
    {
        //取走大量现金事件
        public event BigMoneyFetchedHandler BigMoneyFetched;
        //ATM内部银行
        private string[] bankName= {"中国银行","中国邮政银行","中国建设银行" };
        public void BigMoney(Object sender,BigMoneyArgs nma)
        {
            Console.WriteLine("取走大量金额，共" + nma.Money + "元");
        }
        public string this[int idx]
            {
            get
            {
                return bankName[idx];
            }
            set
            {
                bankName[idx] =value ;
            }
            }
        
        public void getMoney(ref Account account,float money)
        {
            if(money>10000)
            {
                BigMoneyArgs bma = new BigMoneyArgs()
                {
                    Money = money
                };
                //触发事件
                BigMoneyFetched(this, bma);
            }
            Random rd = new Random(10);
            if(rd.Next()<3)
            {
                throw new BadCashException("出现坏钞", 100);
            }
            else
            {
                account.subMoney(money);
            }

        }
        public void storeMoney( ref Account account, float money)
        {
            account.addMoney(money);
        }
    }
}
